package object

import (
	"gddgame.cc/galaxy/common/dsl/game"
	"gddgame.cc/galaxy/common/dsl/game/ai"
	"gddgame.cc/galaxy/common/dsl/game/attr"
	"gddgame.cc/galaxy/common/dsl/game/base"
	"gddgame.cc/galaxy/utils"
)

//go:generate msgp

//msgp:tuple ObjectInfo
type ObjectInfo struct {
	Id       int    `json:"id" msg:"id"`
	Name     string `json:"name" msg:"name"`
	Category int    `json:"category" msg:"category"`
	Identity int    `json:"identity" msg:"identity"`
	Entity   string `json:"entity" msg:"entity"`

	Base     *base.ObjectBaseExt `json:"base" msg:"base"`
	LiveTime int                 `json:"liveTime" msg:"liveTime"`

	Attr      []interface{}      `json:"attr" msg:"attr"`
	Extend    interface{}        `json:"extend" msg:"extend"`
	Ai        interface{}        `json:"ai" msg:"ai"`
	AttrEvent [][]attr.AttrEvent `json:"attrEvent" msg:"attrEvent"`

	*game.DataExtend `json:"-" msg:"-"`
}

func NewObjectInfoFromObject(provider *game.DataProvider, object *SettingObject, base *base.ObjectBaseExt, modes []ai.ModelAi) *ObjectInfo {
	extend := game.NewDataExtend(utils.ToString(object.Id), object.UpdateTime).Add("name", object.Name)
	ext := &ObjectInfo{
		Id:       object.Id,
		Name:     provider.LanguageKey(extend.Inline(), "name"),
		Category: int(object.Category),
		Identity: object.Identity,
		Entity:   object.Entity,

		Base:     base,
		LiveTime: object.LiveTime,
		Attr:     object.Attr.GenerateAttr(),
		Extend:   object.Extend,

		AttrEvent: object.AttrEvent,

		DataExtend: extend,
	}
	if modes != nil {
		ext.Ai = ai.MakeAi(modes)
	}

	return ext
}
